package com.sfh.ship.adapter;

import java.util.List;

import com.sfh.ship.R;
import com.sfh.ship.adapter.MainAdapter.HondlerView;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public abstract class ShipBaseAdapter<T, V> extends BaseAdapter
{
    LayoutInflater mInflater;
    
    int mLayout;
    
    List<T> mList;
    
    public ShipBaseAdapter(Context context, int layout, List<T> list)
    {
        this.mInflater = LayoutInflater.from(context);
        this.mLayout = layout;
        this.mList = list;
    }
    
    @Override
    public int getCount()
    {
        return mList.size();
    }
    
    @Override
    public Object getItem(int arg0)
    {
        return mList.get(arg0);
    }
    
    @Override
    public long getItemId(int arg0)
    {
        return arg0;
    }
    
    @SuppressWarnings("unchecked")
    @Override
    public View getView(int position, View view, ViewGroup parent)
    {
        V mHondler = null;
        if (view == null)
        {
            view = mInflater.inflate(mLayout, parent, false);
            mHondler = findHondView(view);
            view.setTag(mHondler);
        }
        else
        {
            mHondler = (V)view.getTag();
        }
        Object object = getItem(position);
        setViewData((T)object, mHondler);
        return view;
    }
    
    public abstract V findHondView(View view);
    
    public abstract void setViewData(T t, V hondler);
    
}
